
package com.kugou.game.sdk.ui.widget;

import com.kugou.game.sdk.utils.Rx;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

/**
 * 描述:广告控件
 *
 * @author jerryliu
 * @since 2015年8月18日 下午12:10:14
 */
public class AdView extends LinearLayout {

    public AdView(Context context) {
        super(context);
        setFocusable(true);
        setClickable(true);
        setFocusableInTouchMode(true);
        requestFocus();
        requestFocusFromTouch();
        initView(context);
    }

    public AdView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setFocusable(true);
        setClickable(true);
        setFocusableInTouchMode(true);
        requestFocus();
        requestFocusFromTouch();
        initView(context);
    }

    ImageView adShowImg;

    ImageView adCloseImg;

    private void initView(Context context) {
        int adResId = Rx.layout.kg_single_bottom_ad_layout;
        View ad1LayoutView = LayoutInflater.from(context).inflate(adResId, this);
        adShowImg = (ImageView) ad1LayoutView.findViewById(Rx.id.kg_single_bottom_ad_img);
        adCloseImg = (ImageView) ad1LayoutView.findViewById(Rx.id.kg_single_bottom_ad_close_btn);
    }

    public void setOnAdShowImgClickListener(final OnClickListener listener) {
        if (adShowImg != null) {
            adShowImg.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (listener != null) {
                        listener.onClick(v);
                    }
                }
            });
        }
    }

    public void setOnAdCloseImgClickListener(final OnClickListener listener) {
        if (adCloseImg != null) {
            adCloseImg.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (listener != null) {
                        listener.onClick(v);
                    }
                }
            });
        }
    }

    public void setImageBitmap(Bitmap bitmap) {
        if (adShowImg != null && bitmap != null) {
            adShowImg.setImageBitmap(bitmap);
        }
    }
}
